package com.web.service.impl;

import com.web.aspect.MyLog;
import com.web.dao.StudentDAO;
import com.web.entity.PageVO;
import com.web.entity.Student;
import com.web.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 学生业务逻辑实现类
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentDAO studentDAO;
    @Override
    public List<Student> findAllStudents() {
        return studentDAO.selectAllStudents();
    }

    @Override
    public PageVO findStudentPage(int current, int pageSize) {
        //查询学生总数
        int count = studentDAO.selectStudentCount();
        //获得查询的行数
        int start = (current - 1) * pageSize;
        //分页查询学生集合
        List<Student> students = studentDAO.selectStudentPage(start,pageSize);
        return new PageVO(current,pageSize,count,students);
    }

    @MyLog("这是添加学生的方法")
    @Override
    public void addStudent(Student student) {
        studentDAO.insertStudent(student);
    }

    @MyLog("这是更新学生的方法")
    @Override
    public void updateStudent(Student student) {
        studentDAO.updateStudent(student);
    }

    @MyLog("这是删除学生的方法")
    @Override
    public void removeStudent(int id) {
        studentDAO.deleteStudent(id);
    }
}
